﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.IO;

namespace XmlFromOtherFormat
{
    class Program
    {
        static void Main(string[] args)
        {
            XmlDocument doc = new XmlDocument();
            XmlDeclaration declaration = doc.CreateXmlDeclaration("1.0", "UTF-8", "");
            doc.AppendChild(declaration);
            XmlElement newel = doc.CreateElement("albums");
            doc.AppendChild(newel);
            using (XmlTextReader reader = new XmlTextReader("catalog.xml"))
            {
                while (reader.Read())
                {
                    if ((reader.NodeType == XmlNodeType.Element) &&
                   (reader.Name == "album"))
                    {

                        XmlElement album = doc.CreateElement("album");
                        newel.AppendChild(album);
                        reader.Read();
                            XmlElement title = doc.CreateElement("title");
                            album.AppendChild(title);
                            album.AppendChild(title).InnerText = reader.ReadElementString();
                            reader.Read();
                            XmlElement artist = doc.CreateElement("artist");
                            album.AppendChild(artist);
                            album.AppendChild(artist).InnerText = reader.ReadElementString();
                        
                    }
                }
            }

            doc.Save("album.xml");
        }
    }
}
